package com.walala.logic.handler;


import com.walala.logic.annotation.HandlerContract;
import com.walala.logic.common.Command;
import com.walala.logic.common.Constant;
import com.walala.logic.pojo.msg.MsgProtoc;
import com.walala.logic.protocol.IMProto;
import com.walala.logic.protocol.ProtocolPackage;
import com.walala.logic.redis.RedisClient;
import com.walala.logic.service.SendDataService;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

import static com.walala.logic.protocol.IMProto.*;

/**
 * @author KayLi
 */
@HandlerContract(cmd = Command.NOTICE)
public class NoticeHandler implements MsgHandler{
    
    private Logger logger = LoggerFactory.getLogger(NoticeHandler.class);

    @Override
    public void process(ProtocolPackage pack) {

    }

    @Override
    public void process(MsgProtoc msg) {

        Notice.Builder builder = Notice.newBuilder();
        builder.setSenderId(msg.getSenderId());
        builder.setReceiverId(msg.getReceiverId());
        if(StringUtils.isNotEmpty(msg.getSenderName())){
            builder.setSenderName(msg.getSenderName());
        }
        if(StringUtils.isNotEmpty(msg.getMsgBody())){
            builder.setMsgBody(msg.getMsgBody());
        }
        if(StringUtils.isNotEmpty(msg.getExtra())){
            builder.setExtra(msg.getExtra());
        }
        builder.setTime(msg.getTime());
        byte[] protoBody = builder.build().toByteArray();

        ProtocolPackage pack = new ProtocolPackage();
        //pack.setClientType(clientType);
        pack.setCommand(Command.NOTICE);
        pack.setSenderId(msg.getSenderId());
        pack.setStime(msg.getTime());
        pack.setReceiverId(msg.getReceiverId());
        pack.setProtoBody(protoBody);

        SendDataService.send(msg.getReceiverId(),pack);

    }
}
